/**
 * 
 */
package forum.communication;

import forum.server.controller.ForumFacadeInt;
import forum.server.domain.PostContent;
import forum.server.exceptions.*;


/**
 * @author Tamir 
 *
 */
public class AddMessageMessage extends ClientMessage {

	private static final long serialVersionUID = 8912617401305761411L;
	
	/* The content of the message to add. */
	private PostContent content;
	private String header;

	public AddMessageMessage(String header, PostContent content) {
		this.content = content;
		this.header = header;
	}

	/* (non-Javadoc)
	 * @see forum.tcpcommunicationlayer.ClientMessage#doOperation(forum.server.domainlayer.ForumFacade)
	 */
	@Override
	public ServerResponse doOperation(ForumFacadeInt forum) {
		try {
			forum.addPost(this.header, this.content);
			return new ServerResponse("The post was added successfully",true);
		}
		catch (NotLoggedInException e) {
			return new ServerResponse("Guests are not allowed to add posts.\nPlease login.",false);
		} catch (DatabaseException e) {
			return new ServerResponse("The server is currently down for maintanance.\nPlease try again later.",false);
		}
	}

}
